home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / kowin / archive / net / koprosrc.lzh / kopro.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-10  |  5.1 KB  |  255 lines

  1. /*    Copyright 1992 H.Ogasawara(COR.)    */
  2.  
  3. #include    <stdio.h>
  4. #include    <wlib.h>
  5. #include    "proto.h"
  6. #include    "run.h"
  7.  
  8. #define    SIZEH    (6*24)
  9. #define    SIZEV    (30)
  10. #define    COUNTX    (2+30)
  11. #define    COUNTY    (12+2+2)
  12. #define    FNAMEX    (2)
  13. #define    FNAMEY    (2)
  14.  
  15. /*
  16. Xsm  X/Y  Y-G
  17.  
  18. Xsum-Send: 
  19. [Mode] [Receive]   [Exit]
  20.  
  21. Xsum-Send: denden.pro
  22. 0000K (0000/0000)  [Cancel]
  23.  
  24. Receive: program.ttt
  25. [Y-G] 0000K (   0/   0)
  26. */
  27.  
  28. unsigned int    timeout;
  29. unsigned short    runsize;
  30. void        (*run)();
  31.  
  32. unsigned int    size;
  33. unsigned short    block,
  34.         last;
  35.  
  36. unsigned short    autoexit= FALSE,
  37.         batch= FALSE,
  38.         sendflag= FALSE;
  39.  
  40. WindowID    Awp= NULL;
  41.  
  42. int    WindowHeapSize= 0*1024;
  43.  
  44. DispSet( dbuf )
  45. DrawBuf    *dbuf;
  46. {
  47.     static unsigned char    buf[]= {
  48. /*     0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16 */
  49.     ' ',' ',' ',' ','K',' ','(',' ',' ',' ','0','/',' ',' ',' ','0',')','\0'
  50.     };
  51.     unsigned char    *str= buf+4;
  52.     unsigned short    i= size/1024;
  53.     do{
  54.         *--str= i%10+ '0';
  55.     }while( i/= 10 );
  56.     for(; str > buf ; *--str= ' ' );
  57.     str= buf+11;
  58.     i= block;
  59.     do{
  60.         *--str= i%10+ '0';
  61.     }while( i/= 10 );
  62.     for(; str > buf+7 ; *--str= ' ' );
  63.     str= buf+16;
  64.     i= last;
  65.     do{
  66.         *--str= i%10+ '0';
  67.     }while( i/= 10 );
  68.     for(; str > buf+12 ; *--str= ' ' );
  69.     DrawSetSymbol( dbuf, COUNTX, COUNTY, (char*)buf, 9, 12 );
  70.     return    1;
  71. }
  72.  
  73. DispFileSet( dbuf )
  74. DrawBuf    *dbuf;
  75. {
  76.     /*Y-Receive: program.ttt*/
  77.     static char    buf[50];
  78.     static char    *mode[]= { "[Xsm]", "[X/Y]", "[Y-G]",
  79.                 "[???]", "[Y-B]", "[YGB]",
  80.                 "[ X ]", "[X-L]", "[ Y ]\0Copyright 1992 H.Ogasawara(COR.)" };
  81.     strcpy( buf, sendflag ? "Send: " : "Receive: " );
  82.     strcat( buf, sendflag && !*filename ? "ファイル名?" :(char*)filename);
  83.     strcat( buf, "                 " );
  84.     DrawSetSymbol( dbuf, FNAMEX, FNAMEY, buf, 9, 12 );
  85.     DrawSetSymbol( dbuf+1, COUNTX-30, COUNTY, mode[ sendflag ? rettype+6 : batch ? rettype+3 : rettype ], 9, 12 );
  86.     return    2;
  87. }
  88.  
  89. DispFilename()
  90. {
  91.     DrawBuf    dbuf[2];
  92.     WindowDraw( Awp, dbuf, DispFileSet( dbuf ) );
  93. }
  94.  
  95. DispCountup()
  96. {
  97.     DrawBuf    dbuf[1];
  98.     WindowDraw( Awp, dbuf, DispSet( dbuf ) );
  99. }
  100.  
  101. EndProgram()
  102. {
  103.     if( autoexit )
  104.         WindowSendSignal( WindowProcessID, SignalKill, NULL );
  105. }
  106.  
  107. Exec( wp, info )
  108. WindowID    wp;
  109. EventInfo    *info;
  110. {
  111.     DrawBuf    dbuf[8];
  112.     static unsigned char    retbuf[2048],
  113.                 *retptr= retbuf;
  114.     static unsigned short    retsize= 0;
  115.     switch( info->option ){
  116.     case EventInterval:
  117.         if( runsize && ISNS232C() ){
  118.             do{
  119.                 *retptr++= INP232C();
  120.                 if( ++retsize >= runsize ){
  121.                     (*run)( retbuf );
  122.                     retsize= 0;
  123.                     retptr= retbuf;
  124.                     return    TRUE;
  125.                 }
  126.             }while( ISNS232C() );
  127.             return    TRUE;
  128.         }else if( timeout && ONTIME() >= timeout ){
  129.             (*run)( NULL );
  130.             return    TRUE;
  131.         }
  132.         return    FALSE;
  133.     case EventOpen:
  134.         WindowSetEventAttr( Awp= wp, EventOpenON|EventCloseON|
  135.             EventKeyON|EventUserON|
  136.             EventRedrawON|EventMouseSwitchON|EventIntervalON );
  137.         WindowRedraw( wp );
  138.         if( autoexit ){
  139.             if( sendflag ){
  140.                 if( *filename )
  141.                     SendStart();
  142.             }else
  143.                 ReceiveStart();
  144.         }
  145.         return    TRUE;
  146.     case EventRedraw:
  147.         DrawSetClear( dbuf, 1 );
  148.         DispSet( dbuf+1 );
  149.         DispFileSet( dbuf+2 );
  150.         WindowDraw( wp, dbuf, 4 );
  151.         return    TRUE;
  152.     case EventClose:
  153.         CloseFile();
  154.         if( autoexit ){
  155.             unsigned int    pid;
  156.             if( pid= PidSearch( "k20.win", 1 ) ){
  157.                 info->option= EventUser;
  158.                 info->ComData= 'k20';
  159.                 info->ComBuffer= "i1";
  160.                 WindowSendEventAll( pid, info );
  161.             }
  162.         }
  163.         WindowClose( wp );
  164.         WindowConnectionClose();
  165.         return    TRUE;
  166.     case EventMouseSwitch:
  167.         return    TRUE;
  168.     case EventKey:
  169.         if( info->KeyCode == 3 || info->KeyCode == ('x'&0x1f) ){
  170.             Write232C( CAN );
  171.             Write232C( CAN );
  172.             Write232C( CAN );
  173.             Write232C( CAN );
  174.             allbreak();
  175.         }
  176.         return    TRUE;
  177.     case EventUser:
  178.         if( sendflag && !*filename ){
  179.             switch( info->ComData ){
  180.             case UserPaste:
  181.             case UserString:
  182.                 strcpy( filename, info->ComBuffer );
  183.                 DispFilename();
  184.                 SendStart();
  185.                 break;
  186.             case UserStrings:
  187.                 strcpy( filename, *(char**)info->ComBuffer );
  188.                 DispFilename();
  189.                 SendStart();
  190.                 break;
  191.             }
  192.         }
  193.         return    TRUE;
  194.     }
  195.     return    FALSE;
  196. }
  197.  
  198. WindowMain( argc, argv )
  199. char    **argv;
  200. {
  201.     int    x= 80,
  202.         y= 80;
  203.     *filename= '\0';
  204.     argc= AnalyzeArgs( argc, argv, &x, &y, NULL, NULL );
  205.     while( --argc ){
  206.         if( **++argv == '-' ){
  207.             switch( *++*argv|0x20 ){
  208.             case 'a':
  209.                 autoexit= TRUE;
  210.                 break;
  211.             case 'b':
  212.                 batch= TRUE;
  213.                 break;
  214.             case 'r':
  215.                 switch( *++*argv|0x20 ){
  216.                 case 'x':
  217.                 case 's':    /* -rsum */
  218.                     rettype= 0;
  219.                     break;
  220.                 case 'y':
  221.                 case 'c':    /* -rcrc */
  222.                     rettype= 1;
  223.                     break;
  224.                 case 'g':
  225.                     rettype= 2;
  226.                     break;
  227.                 }
  228.                 break;
  229.             case 's':
  230.                 sendflag= TRUE;
  231.                 switch( *++*argv|0x20 ){
  232.                 case 'x': /* 128 */
  233.                     rettype= 0;
  234.                     break;
  235.                 case 'l':
  236.                     rettype= 1;
  237.                     break;
  238.                 case 'y':
  239.                     rettype= 2;
  240.                     break;
  241.                 }
  242.                 break;
  243.             case 'd':
  244.                 if( *++*argv == 'd' ){
  245.                     extern unsigned char downdir[];
  246.                     strcpy( downdir, (*argv)+1 );
  247.                 }
  248.                 break;
  249.             }
  250.         }else
  251.             strcpy( filename, *argv );
  252.     }
  253.     WindowTitleOpen( x, y, SIZEH, SIZEV, NULL, "KoPro 1.16", Close|Push, Exec );
  254. }
  255.